<template>
  <div class="right">
    <div class="top">
      <el-radio-group v-model="form.labelPosition" size="small">
        <el-radio-button label="left">节点内容配置</el-radio-button>
        <el-radio-button label="right">判读依据配置</el-radio-button>
      </el-radio-group>
    </div>
    <div class="pl-20">
      <!-- <h3>{{ info.nodeName }}</h3> -->
      <div>
        <div class="title">
          <span class="high" />
          配置内容1
        </div>
        <el-form class="bor p-20">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="节点名称">
                <el-input v-model="info.nodeName" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="节点类型">
                <el-select
                  v-model="info.deviceId"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item,idx) in dict"
                    :key="idx"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="执行内容">
                <el-input v-model="info.remark" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="执行次数">
                <el-input v-model="info.nodeData" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="mt-20">
        <div class="title">
          <span class="high" />
          配置内容2
        </div>
        <el-form class="bor p-20">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item
                :label="info.optionType == 1 ? '设备列表' : '仪器列表'"
              >
                <!-- <el-input v-model="info.nodeName" /> -->
                <el-select
                  v-if="info.optionType == 1"
                  v-model="info.deviceId"
                  placeholder="请选择"
                  style="width: 100%"
                  @change="getOrder"
                >
                  <el-option
                    v-for="(item,idx) in devicelist"
                    :key="idx"
                    :label="item.deviceName"
                    :value="item.deviceId"
                  />
                </el-select>
                <el-select
                  v-else
                  v-model="info.instrumentId"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item,idx) in machinelist"
                    :key="idx"
                    :label="item.instrumentName"
                    :value="item.instrumentId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="指令">
                <el-select
                  v-model="info.comdId"
                  placeholder="请选择"
                  style="width: 100%"
                  @change="orderMethod"
                >
                  <el-option
                    v-for="(item,idx) in order"
                    :key="idx"
                    :label="item.comdName"
                    :value="item.comdId"
                  />
                </el-select>
                <!-- <el-input v-model="info.remark" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="指令描述">
                <el-input v-model="info.comdDesc" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="指令代号">
                <el-input v-model="info.comdCode" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="指令值">
                <el-input v-model="info.comdData" placeholder="请设置" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="关联判读指令参数列表">
                <el-select
                  v-model="info.connect"
                  placeholder="请选择"
                  style="width: 100%"
                  @change="orderMethod"
                >
                  <el-option
                    v-for="(item,idx) in judgeList"
                    :key="idx"
                    :label="item.parmName"
                    :value="item.parmId"
                  />
                </el-select>
                <!-- <el-input v-model="info.remark" /> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="mt-20">
        <div class="title">
          <span class="high" />
          配置内容3
        </div>
        <judge />
      </div>
    </div>
  </div>
</template>

<script>
import judge from './judge'
import { addScene, orderList, getParmByComdList } from '@/api/form'
import { getOperateTypeList, getOperateDataByType } from '@/api/dict'
import { getDeviceList, getMachineList } from '@/api/table'
export default {
  name: 'NodeConfiguration',
  components: {
    judge
  },
  data() {
    return {
      form: { labelPosition: 'left' },
      info: { comdData: '' },
      optionType: '',
      devicelist: [],
      machinelist: [],
      dict: [],
      order: [],
      judgeList: []
    }
  },
  watch: {
    info: {
      handler(val) {
        console.log('info', val)
      },
      deep: true
    }
  },
  mounted() {
    getOperateDataByType().then((res) => {
      console.log(res)
      this.dict = res.data
    }),
    getDeviceList({
      pageSize: 1,
      pageNum: 1000
    }).then((res) => {
      this.devicelist = res.rows
    }),
    getMachineList({
      pageSize: 1,
      pageNum: 1000
    }).then((res) => {
      this.machinelist = res.rows
    })
  },
  methods: {
    getOrder(val) {
      const code = this.devicelist.filter(item => item.deviceId == val)[0].dictCode
      orderList({ dictCode: code }).then(res => {
        console.log(res)
        this.order = res.data
      })
    },
    orderMethod(val) {
      const data = this.order.filter((item) => item.comdId == val)[0]
      const obj = {}
      if (data.comdData == null) {
        data.comdData = ''
      }
      // this.info = Object.assign(this.info, data)
      this.info = { ...this.info, ...data }
      // this.info.comdData = ''
      console.log(this.info)
      getParmByComdList({ comdId: val }).then(res => {
        console.log(res)
        this.judgeList = res.rows
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.p-20 {
  padding-top: 20px;
  padding-right: 20px;
  padding-left: 20px;
}
::v-deep .el-form-item__label {
  color: white;
}
.top {
  height: 40px;
  margin-bottom: 20px;
  padding-left: 10px;
  padding-left: 20px;
  text-align: left;
  color: white;
  background: rgba(17, 91, 122, 0.5);
  line-height: 40px;
  i {
    float: right;
    margin-top: 12px;
    margin-right: 10px;
    cursor: pointer;
    color: rgb(0, 193, 254);
  }
}
.pl-20 {
  padding-left: 20px;
}
h3 {
  color: white;
}
.left {
  width: 20%;
  height: 100vh;
  border-right: 1px solid rgb(26, 102, 133);
}
.right {
  flex: 1;
  // padding-left: 20px;
}
.part {
  height: 52px;
  margin-bottom: 20px;
  background: rgba(26, 57, 78, 0.6);
  .el-form {
    margin-top: 8px;
  }
}
.bor {
  border: 0.5px solid rgb(1, 190, 249);
}
.title {
  width: 120px;
  height: 32px;
  margin-left: 0;
  padding-left: 20px;
  color: white;
  background: url("../../assets/img/highlight.svg");
  background-size: 100% 100%;
  font-size: 14px;
  line-height: 32px;
}
</style>
